Ext.define('CMS.controllers.login.LoginWinController',{

    extend:'Ext.app.ViewController',
    alias:'controller.LoginWinController',


    login: function() {
        if(this.lookup('form').isValid()){
            Ext.Msg.alert('Login Demo', '<span class="fa fa-smile-o"></span> Thank you for reading my post!');
        }
        },

    onSubmitButtonClick: function(button, event) {
        //登陆
        var me = this,
            window = me.getView(),
            form = window.down('form');
        var formValues = form.getValues();
        var un= formValues['username'];
        Ext.Msg.alert('Login Demo '+un);
        Ext.Ajax.request({
            method: 'post',
            url: 'http://localhost:8080/login/login.do',
            params: formValues,
            success:function(response,options){
                if(Ext.util.JSON.decode(response.responseText)==true){
                    Ext.Msg.alert('成功', '从服务端获取结果: ' + response.responseText);
                    //this.getView().destroy();
                    window.destroy();
                    Ext.create({
                        xtype:'Main'
                    });
                }else{
                    Ext.Msg.alert('登录失败','账号或者密码错误');
                }

                // Ext.Msg.alert('成功', '从服务端获取结果: ' + response.responseText);
            },
            failure:function(response,options){
                Ext.Msg.alert('失败', '请求超时或网络故障,错误编号：' + response.status);
            }
        });
    },

    onRegisterButtonClick: function(button, event) {
        //注册
        this.getView().destroy();
        Ext.create({
            xtype:'LogupWinLink'
        });
    },

    onEnterPress: function(field, event, eOpts) {
        //按ENTER键
        if (event.getKey() == event.ENTER) {
            this.onSubmitButtonClick();
        }
    }

})